define(function(require, exports){
	var $       = require("jquery");
	var util    = require('util');
	var pubjs   = require('pubjs');
	var view    = require('@base/view');
	var utilDSP = require('modules/common');

	var Main = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'P-brand-blacklist',
				'isSubGrid': false,
				'hasHead': true, // 是否有头部标题
				'grid_config': null, // 列表配置
				'gridName': 'customer',
				'view_model':{
					'view': {
						'addButton': true
					}
				}
			});
			this.Super('init', arguments);
		},
		afterBuild:function(){
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM();

			self.append($([
				'<div class="M-formHead">',
					'<span ms-visible="view.addButton" class="ml10" pub-name="addButton" pub-mod="@base/common/drop.add" ></span>',
				'</div>',
				'<div class="cl" pub-name="highGrid" pub-mod="admin/blacklist/grid/blacklist.base"/>',
			].join('')));

			var config = {
				'addButton': {
					'def': LANG('新建黑名单'),
					'href': '#admin/blacklist/edit',
					'href_target': '_self',
				},
				'highGrid': util.extend(c.grid_config, {
					'hasBatch': true,
					'eventDataLoad': true,
					'hasSearch': true,
					'gridName': 'blacklist'
				})
			};
			self.buildFromTemplate(config);

			self.createAsync('slotSidebar', '@layout/v1/sidebar.base', {
				'target': c.targetSidebar,
				'items': [
					{'name': 'status', 'uri':'modules/sideBarBase.radio', 'config': {
						'title': LANG('状态：'),
						'data': [
							{id: 0, name: LANG('所有')},
							{id: 1, name: LANG('开启')},
							{id: 2, name: LANG('关闭')},
							{id: 3, name: LANG('归档')},
						],
						'value': 0
					}},
					{'name': 'advertiserId', 'uri':'modules/sideBarBase.aderGridGroup', 'config': {
						'title': LANG('广告主：'),
						'url': 'qualification/list',
					}},
				]
			});
		},
		reload: function(param){
			this.$.highGrid.setParam(param).load();
			return this;
		},
		onSidebarFilter: function(ev){
			var self = this,param = {};

			util.each(ev.param, function(item, idx){
				var type = idx;
				var id = item.id;

				switch (type) {
					case 'status':
						param.Status = +id;
						break;
					case 'advertiserId':
						param.AdvertiserId = item.data.length ? item.data : [];
						break;
				}
			});

			self.$.highGrid.setParam(param).load();
		}
	});
	exports.main = Main;
});